def nearest_prime():

    input_numbers = input().split()
    if len(input_numbers) != 3: 
        return "Wrong input"

    numbers_dict = { "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9 }

    number = numbers_dict.get(input_numbers[0], 0) * 100 + numbers_dict.get(input_numbers[1], 0) * 10 + numbers_dict.get(input_numbers[2], 0)
    if not 100 <= number <= 999: 
        return "Wrong input"

    def is_prime(n):
        if n <= 1:
            return False
        for i in range(2, int(n ** 0.5) + 1): 
            if n % i == 0: 
                return False
        return True

    smaller = number
    larger = number
    while True: 
        smaller -= 1
        if is_prime(smaller):
            return smaller
        if is_prime(larger):
            return larger
        larger += 1

print(nearest_prime())
